package com.xbw.bookSale.biz;

import java.sql.Connection;
import java.sql.SQLException;

import com.xbw.bookSale.dao.*;

public class InitBiz {

	public void initShop() {

		BookDAO book_dao = new BookDAO();
		BookTypeDAO type_dao = new BookTypeDAO();
		Connection conn = null;
		boolean defaultCommit = false;
		try {
			conn = BaseDAO.getConnection();
			defaultCommit = conn.getAutoCommit();
			conn.setAutoCommit(false);
			book_dao.setConn(conn);
			type_dao.setConn(conn);
			book_dao.deleteAll();
			type_dao.deleteAll();
			conn.commit();
		} catch (SQLException e) {
			e.printStackTrace();
			try {
				conn.rollback();
			} catch (SQLException e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				conn.setAutoCommit(defaultCommit);
			} catch (SQLException e) {
				e.printStackTrace();
			}
			book_dao.getClose();
			type_dao.getClose();
		}
	}

}
